package com.gxar.navigation.server.base.controller;

import com.fusion.redis.annotations.LockNamePostfix;
import com.fusion.redis.annotations.RedissonLock;
import com.gxar.common.entity.Result;
import com.gxar.navigation.server.base.model.route.vo.request.DirectionRequest;
import com.gxar.navigation.server.base.model.route.vo.response.DirectionResponse;
import com.gxar.navigation.server.db.service.RouteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

/**
 * @author linsy
 * @version 1.0
 * @created 2023/9/15 14:50
 */
@Api(tags = "地图路线规划视图层")
@RestController
@RequestMapping("/api/map/route")
@RequiredArgsConstructor
@Slf4j
public class RouteController {

    private final RouteService routeService;

    @ApiOperation("GPS路线规划")
    @PostMapping("/gps/direction/{active-id}")
    public Result<DirectionResponse> direction(@PathVariable("active-id") Long activeId, @RequestBody DirectionRequest directionRequest) {
        DirectionResponse response = routeService.direction(activeId, directionRequest);
        return Result.success(response);
    }

    @GetMapping("sync")
    public Result<Boolean> sync(@LockNamePostfix(value = "id") @RequestParam("id") String id) {
        routeService.getNodeList(Long.parseLong(id));
        routeService.getLineList(Long.parseLong(id));
        return Result.success();
    }
}
